import type { UserItemForm, UserPageListItem } from './model/userModel'

import type { ApiPagination, ApiPaginationParams } from '#types/utils'

import { requestClient } from '../request'

// 用户管理
export default class SysUserApi {
    static get inst() {
        return SysUserApi._inst || (SysUserApi._inst = new SysUserApi())
    }
    private static _inst: SysUserApi
    /**
     * 新增用户
     * @param params

     */
    add(params: Partial<UserItemForm>) {
        return requestClient.post<null>('/user/add', params)
    }

    delete(ids: Array<number | string>) {
        return requestClient.delete<null>(`/user/delete/${ids}`)
    }

    /**
     * 编辑用户信息
     * @param id
     * @param params
     */
    edit(id: number | string, params: Partial<UserItemForm>) {
        return requestClient.put<null>(`/user/edit/${id}`, params)
    }

    /**
     * 用户管理分页
     * @param params

     */
    getPageList(params: ApiPaginationParams<{ username?: string }>) {
        return requestClient.get<ApiPagination<UserPageListItem>>('/user/index', {
            params
        })
    }

    /**
     * 重置密码
     */
    resetPwd(params: { id: number; password: string }) {
        return requestClient.put<null>('/user/resetPwd', params)
    }

    /**
     * 更新用户状态
     */
    updateStatus(params: { id: number; status: number }) {
        return requestClient.put<null>('/user/status', params)
    }
}
